package com.demo.day418;

public class Josephusproblem {
    /**
     * @Auther: 86176
     * @Date: 2021/4/18 - 04 - 18 - 15:06
     * @Description: com.demo.day418
     * @version: 1.0
     * 
     */
    public static void main(String[] args) {

        int n = 10; //n为参加游戏的人数

        int rem = n, count = 1, cur = 0;

        boolean[] input = new boolean[n];//用数组做标记

        while (true) {

            if (rem == 1) break;

            while (input[cur]) cur = (cur + 1) % n; //巧妙，保证循环转圈圈

            if (count < 3) ++count;

            else {

                count = 1;

                input[cur] = true;

                --rem;

            }

            cur = (cur + 1) % n;//巧妙，保证循环转圈圈

        }

        for (int i = 0; i < n; ++i) {

            if (input[i] == false) {

                System.out.println(i + 1);

                break;

            }

        }

    }

}
